package com.cj.dao.impl;

import com.cj.dao.AdminDao;
import com.cj.entity.Admin;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 管理员数据持久层  实现类
 */
public class AdminDaoImpl extends BaseDaoImpl implements AdminDao {

    /**
     * 管理员登录方法
     * @param account
     * @param password
     * @return
     */
    @Override
    public Admin login(String account, String password) {
        Admin admin = null;
        String sql = "select * from admin where account = '" + account + "' and password = '" + password + "'";
        ResultSet rst = query(sql);
       try{
           if(rst != null){
               //判断是否有下一条数据
               if(rst.next()){
                    int id = rst.getInt("id");
                    String account_new = rst.getString("account");
                    String password_new = rst.getString("password");
                    String name = rst.getString("name");
                    admin = new Admin(account_new, password_new);
                    admin.setName(name);
               }
           }
       } catch (SQLException throwables) {
           throwables.printStackTrace();
       }

        return admin;
    }
}
